package com.hrt.datasender.process.heartbeat.hj212;

import java.util.Date;

import com.hrt.datasender.datadao.model.BcSendPlatformModel;
import com.hrt.datasender.process.heartbeat.IHeartbeat;

public abstract class HeartbeatBase implements IHeartbeat {

    private Date lastHeartbeatTime;
    private final int millTrans = 1000;

    @Override
    public String getHeartBeatData(BcSendPlatformModel platform) {

        if (lastHeartbeatTime == null) {
            lastHeartbeatTime = new Date();
        }

        String data = getData(platform);
        Date curDate = new Date();

        long timeDiff = (curDate.getTime() - lastHeartbeatTime.getTime()) / millTrans;

        if (timeDiff > getInterval()) {
            lastHeartbeatTime = curDate;
            return data;
        }

        return null;
    }

    public abstract String getData(BcSendPlatformModel platform);

    public Date getLastHeartbeatTime() {
        return lastHeartbeatTime;
    }

    public abstract int getInterval();

}
